#include "process.h"
#include <stdlib.h>
#include <stdio.h>

listProcess createListProcess(void) {
	listProcess l;

	l = (listProcess)malloc(sizeof(struct _LINKED_LIST_PROCESS));

	if(l == NULL) {
		return NULL;
	} else {
		l->size = 0;
		l->head = NULL;
		
		return l;
	}
}

int insertNodeProcess(listProcess l,int pid, int type) {
	nodeProcess node;
	nodeProcess new_node;

	node = l->head;

	new_node = (nodeProcess)malloc(sizeof(struct _NODE_PROCESS));
	new_node->pid = pid;
	new_node->type = type;
	new_node->next = NULL;

	if(new_node == NULL) {
		return 0;
	} 

	if(node == NULL) {
		l->head = new_node;
		(l->size)++;
		return 1;
	} else {
		while(node->next != NULL) {
			node = node->next;
		}

		node->next = new_node;
		(l->size)++;
		return 1;
	}
}

void printProcess(listProcess l) {
	nodeProcess node = l->head;
	
	printf("---------------\n");
	printf("Process Running\n");
	printf("---------------\n\n");
	while(node != NULL) {
		printf(" Process id: %d\n",node->pid);
		node = node->next;
	}
	printf("\n");
}
